package com.cheng.chat;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;
//循环接收
public class UDPReceiveDemon01 {
    public static void main(String[] args) throws Exception {

        //建立socket连接
        DatagramSocket socket = new DatagramSocket(6666);



        while(true){  //循环接收
            byte[] bytes = new byte[1024];//缓冲区存放数据
            DatagramPacket packet = new DatagramPacket(bytes,0,bytes.length);//把数据返回成数据包
            socket.receive(packet);//socket阻塞式接收包裹



            //断开连接请求
            byte[] data = packet.getData();
            String receivedate = new String(data,0,data.length);

            System.out.println(receivedate);

            if (receivedate.equals("再见")){
                break;
            }




        }
        socket.close();


    }
}
